<template>
  <div>
    <!-- 发票签收 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      columnsRef="qjhInvoiceSign"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" :disabled="!isCan" @click="signHandle">签 收</el-button>
      </template>
    </FilterTable>

    <BaseDialog :visible.sync="isSign" :title="'签收'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" width="72%">
      <SignModel :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>

    <BaseDialog :visible.sync="visible" title="物流信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList } from '@/api/dealerFinance/InvoiceManage/InvoiceSign';
import SignModel from './SignModel';
import SonModel from './SonModel';

export default {
  name: 'InvoiceSign',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      visible: false,
      isCan: false,
      isSign: false,
      invoiceIds: []
    };
  },
  components: {
    SignModel,
    SonModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    signHandle() {
      this.formData.invoiceIds = this.invoiceIds;
      this.isSign = true;
    },
    selectChangeHandle(row) {
      this.invoiceIds = [];
      if (row.length > 0) {
        this.isCan = true;
        row.map(x => {
          this.invoiceIds.push(x.invoiceId);
        });
        return;
      }
      this.isCan = false;
    },
    detailHandle(row) {
      this.visible = true;
      this.formData = row;
    },
    emitCloseHandler(val, type) {
      this.isSign = val;
      this.visible = val;

      if (type == 'refresh') {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '快递单号',
          fieldName: 'courierNo',
          placeholder: '请输入'
        },
        {
          type: 'RANGE_DATE',
          label: '快递日期',
          fieldName: 'courierStrartDate|courierEndDate',
          initialValue: [],
          dateType: 'exactdaterange'
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择',
          itemList: this.createDictList('6008')
        },
        {
          type: 'INPUT',
          label: '发票号',
          fieldName: 'goldenInvoiceNo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '快递公司',
          fieldName: 'courierCompany',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '业务类型',
          fieldName: 'buzinessType',
          placeholder: '请选择',
          itemList: this.createDictList('6089')
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '动力形式',
          dataIndex: 'powerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6008'),
          render: props => {
            return <span>{this.createDictText(props.row.powerType, '6008')}</span>;
          }
        },
        {
          title: '业务类型',
          dataIndex: 'buzinessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6089'),
          render: props => {
            return <span>{this.createDictText(props.row.buzinessType, '6089')}</span>;
          }
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '发票号码',
          dataIndex: 'goldenInvoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发票代码',
          dataIndex: 'goldenInvoiceCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '邮寄状态',
          dataIndex: 'postType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6090'),
          render: props => {
            return <span>{this.createDictText(props.row.postType, '6090')}</span>;
          }
        },
        {
          title: '快递公司',
          dataIndex: 'courierCompany',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '快递单号',
          dataIndex: 'courierNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if (props.row.courierNo) {
              return (
                <el-link type="primary" underline={false} onClick={() => this.detailHandle(props.row)}>
                  {props.row.courierNo}
                </el-link>
              );
            }
          }
        },
        {
          title: '快递日期',
          dataIndex: 'courierDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
<style scoped>
.el-link {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  position: relative;
  text-decoration: none;
  outline: none;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  font-weight: 500;
}
</style>
